<template>
  <el-dialog v-el-drag-dialog title="修改地块信息" :visible.sync="dialogFormVisible">
    <el-form
      ref="dataForm"
      :rules="rules"
      :model="temp"
      label-position="left"
      label-width="150px"
    >
      <el-form-item label="地块名称" prop="placeName">
        <el-input v-model="temp.placeName" />
      </el-form-item>
      <el-form-item label="地块作物，牲畜" prop="produce">
        <el-input v-model="temp.produce" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" @click="modifiedData()">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import elDragDialog from '@/directive/el-drag-dialog'

export default {
  name: 'MyDialog',
  directives: { elDragDialog },
  props: {
    temp: {
      type: Object,
      required: true
    },
    dialogFormVisible: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      rules: {
        placeName: [
          {
            type: 'string',
            required: true,
            message: '请填写地块名称',
            trigger: 'change'
          }
        ],
        produce: [
          {
            type: 'string',
            required: true,
            message: '地块作物，牲畜',
            trigger: 'change'
          }
        ]
      }
    }
  },
  watch: {
    dialogFormVisible() {
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    }
  },
  methods: {
    modifiedData() {
      this.$emit('modified-data')
    }
  }
}
</script>
